package cn.gpnu.util;

import com.mysql.cj.xdevapi.Session;

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Properties;

public final class MailUtils {
    private static final String USER = "";      //发件人称号，同邮箱地址
    private static final String PASSWORD = "";

    /*
    * to:收件人邮箱
    * text：邮箱正文
    * title：标题
    *
    * */

    public static boolean send_mail(String to,String text,String title){
        try {
            final Properties props = new Properties();
            props.put("main.smtp.auth","true");
            props.put("mail.smtp.host","smtp.qq.com");

            //发件人账号
            props.put("mail.user",USER);
            //发件人密码
            props.put("mail.password",PASSWORD);
            //构建授权信息，用于进行SMTP进行身份验证
            Authenticator authenticator = new Authenticator() {
//                @Override
//                protected PasswordAuthentication getPasswordAuthentication() {
//                  String username = props.getProperty("mail.user");
//                  String password = props.getProperty("mail.password");
////                  return new PasswordAuthentication(username,password);
//                }
            };
            //使用环境属性何授权信息，创建邮件会话
//            Session mailsession = Session.getInsrance();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }
}
